# Maintainer: Jonas Witschel <diabonas@archlinux.org>
pkgname=texworks
pkgver=0.6.8
_tag=605a1c74393fb84acdf7dc9d8cf42d154d9de719 # git rev-parse "release-$pkgver"
pkgrel=1
pkgdesc='Unicode-based, TeX-aware editor with integrated PDF viewer'
arch=('loong64' 'x86_64')
url='https://www.tug.org/texworks/'
license=('GPL')
depends=('hunspell' 'libsynctex' 'poppler-qt5' 'qt5-base' 'qt5-declarative' 'qt5-script' 'libpoppler-qt5.so')
makedepends=('git' 'cmake' 'lua' 'python' 'qt5-tools')
checkdepends=('gsfonts' 'poppler-data' 'xorg-server-xvfb')
optdepends=('gsfonts: correctly display PDF files without embedded fonts'
            'lua: Lua scripts support'
            'poppler-data: correctly display certain CJK documents'
            'python: Python scripts support'
            'texlive-core: typeset TeX documents')
source=("git+https://github.com/TeXworks/texworks.git?signed#tag=$_tag")
sha512sums=('SKIP')
validpgpkeys=('8740ED04AF6A4FCC6BC51C426806F10000582F84'
              '21BC42D38D1B03BE59F7A8F15016D150EA64A3D9') # Stefan Löffler (TeXworks) <st.loeffler@gmail.com>

pkgver() {
	cd "$pkgname"
	git describe | sed 's/^release-//;s/\([^-]*-\)g/r\1/;s/-/./g'
}

build() {
	cmake -B build \
	      -S "$pkgname" \
	      -DCMAKE_BUILD_TYPE=None \
	      -DCMAKE_INSTALL_PREFIX=/usr \
	      -DTW_BUILD_ID='Arch Linux' \
	      -DWITH_PYTHON=ON
	cmake --build build
}

check() {
	cd build
	xvfb-run ctest --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}
